package com.zhuqi.overkey;


import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

/**
 * <p>监听redis key 过期事件</p>
 * Copyright: Copyright (C) 2023 YinTa, Inc. All rights reserved.
 * @author zhuqi
 * @since 2023/4/13 10:37
 */
@Slf4j
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {

	public RedisKeyExpirationListener(RedisMessageListenerContainer redisMessageListenerContainer) {
		super(redisMessageListenerContainer);
	}

	/**
	 * 针对 redis 数据失效事件，进行数据处理
	 */
	@Override
	public void onMessage(Message message, byte[] pattern) {
		// 拿到key
		log.info("监听Redis key过期，key：{}，channel：{}", message.toString(), new String(pattern));
	}
}
